a=[
    {"id":1,"类别":"吃饭支出","账户":"交通银行","金额":"195.8","时间":" 2016-03-02","说明":"家庭聚餐"},
    {"id":2,"类别":"工资收入","账户":"现金   ","金额":"3030.0","时间":"2016-03-03","说明":"开工资了"},
    {"id":3,"类别":"服装支出","账户":"工商银行","金额":"168.0","时间":" 2016-03-04","说明":"买衣服"},
    ]

def user():
    while True:
        print("1.查询所有 2.按条件查询")
        kb=input("请输入1 或 2:")
        if kb=="1":
            queryall()
        elif kb=="2":
            queryselect()
        else:
            print("输入错误，请重新输入")
            continue
def admin():
    while True:
        print("1.添加账务 2.编辑账务 3.删除账务 4.查询账务 5.退出系统")
        number=input("请输入要操作的功能序号[1-5]:")
        if number=="1":
            add()
        elif number=="2":
            edit()
        elif number=="3":
            delete()
        elif number=="4":
            queryall()
        elif number=="5":
            print("退出系统！")
            break
        else:
            print("输入错误，请重新输入！")
            continue
def add():
    global a
    aa = {"id": 3, "类别": "", "账户": "", "金额": "", "时间": " ", "说明": ""}
    aa["id"]=len(a)+1
    aa["类别"]=input("请输入类别：")
    aa["账户"]=input("请输入账户：")
    aa["金额"]=input("请输入金额：")
    aa["时间"]=input("请输入时间：")
    aa["说明"]=input("请输入说明：")
    a.append(aa)
    print("添加账务成功！")
def edit():
    global a
    edit=int(input("请输入需要编辑的账务ID:"))-1
    a[edit]["类别"]=input("请输入编辑类别：")
    a[edit]["账户"]=input("请输入编辑账户：")
    a[edit]["金额"]=input("请输入编辑金额：")
    a[edit]["时间"]=input("请输入编辑时间：")
    a[edit]["说明"]=input("请输入编辑说明：")
    print("编辑成功！")
def delete():
    global a
    de=int(input("请输入id:"))-1
    a.pop(de)
def queryselect():
    id_qs=int(input("请输入id:"))-1
    id_ind=a[id_qs]
    print("id", "    类别", "       账户", "        金额", "        时间", "            说明")
    info="%s      %s     %s      %s      %s      %s"
    print(info % ( id_ind["id"], id_ind["类别"], id_ind["账户"], id_ind["金额"], id_ind["时间"], id_ind["说明"]))
def queryall():
    print("id", "    类别", "       账户", "      金额", "        时间", "            说明")
    for i in a:
        info="%s      %s     %s    %s      %s      %s"
        print(info % (i["id"],i["类别"],i["账户"],i["金额"],i["时间"],i["说明"]))
def login():
    ci=0
    while True:
        u=input("请输入账号：")
        p=input("请输入密码：")
        if u=="lisi" and p=="123456":
            user()
            break
        elif u=="admin" and p=="123456":
            admin()
            break
        else:
            print("账户号密码错误!")
            ci += 1
            if ci>=3:
                print("账户密码输入错误3次，程序结束！")
                break
            continue
login()
